<template>
  <div>
    <el-dialog
      :visible.sync="dialog.add"
      :close-on-click-modal="false"
      title="添加"
      width="80%"
      append-to-body
      @closed="dialogClosed('addForm')"
    >
      <el-form ref="addForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户手机号" prop="userPhone">
              <el-input v-model="form.userPhone" placeholder="请输入用户手机号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户手机号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户昵称" prop="userNickname">
              <el-input v-model="form.userNickname" placeholder="请输入用户昵称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户昵称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="内部单号" prop="orderNo">
              <el-input v-model="form.orderNo" placeholder="请输入内部单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="外部交易号" prop="transactionNo">
              <el-input v-model="form.transactionNo" placeholder="请输入外部交易号" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="提现方式" prop="withdrawType">
              <el-select
                v-model="form.withdrawType"
                placeholder="请选择提现方式"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.withdrawTypeSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="发起提现的应用" prop="withdrawClientApp">
              <el-select
                v-model="form.withdrawClientApp"
                placeholder="请选择发起提现的应用"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.withdrawClientAppSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="提现金额（元）" prop="amount">
              <el-input-number
                v-model="form.amount"
                placeholder="请输入提现金额（元）"
                clearable
                style="width: 100%;"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="银行名称" prop="bankName">
              <el-input v-model="form.bankName" placeholder="请输入银行名称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserBankcardMain'
              })"
              >选择银行名称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="银行卡号" prop="bankcardNo">
              <el-input v-model="form.bankcardNo" placeholder="请输入银行卡号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserBankcardMain'
              })"
              >选择银行卡号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="提现状态" prop="withdrawStatus">
              <el-select
                v-model="form.withdrawStatus"
                placeholder="请选择提现状态"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.withdrawStatusSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
            <el-form-item label="提现描述" prop="withdrawDescription">
              <el-input
                type="textarea"
                v-model="form.withdrawDescription"
                placeholder="请输入提现描述"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="审核人手机号" prop="checkedUserPhone">
              <el-input v-model="form.checkedUserPhone" placeholder="请输入审核人手机号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择审核人手机号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="审核人昵称" prop="checkedUserNickname">
              <el-input
                v-model="form.checkedUserNickname"
                placeholder="请输入审核人昵称"
                disabled
                clearable
              />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择审核人昵称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="审核时间" prop="checkedTime">
              <el-date-picker
                type="datetime"
                v-model="form.checkedTime"
                placeholder="请输入审核时间"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%;"
                clearable
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="完成时间" prop="completeTime">
              <el-date-picker
                type="datetime"
                v-model="form.completeTime"
                placeholder="请输入完成时间"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%;"
                clearable
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.add = false">取消</el-button>
        <el-button type="primary" @click="add" :loading="loading.add">添加</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialog.edit"
      :close-on-click-modal="false"
      title="修改"
      width="80%"
      append-to-body
      @closed="dialogClosed('editForm')"
    >
      <el-form ref="editForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户手机号" prop="userPhone">
              <el-input v-model="form.userPhone" placeholder="请输入用户手机号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户手机号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="用户昵称" prop="userNickname">
              <el-input v-model="form.userNickname" placeholder="请输入用户昵称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择用户昵称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="内部单号" prop="orderNo">
              <el-input v-model="form.orderNo" placeholder="请输入内部单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="外部交易号" prop="transactionNo">
              <el-input v-model="form.transactionNo" placeholder="请输入外部交易号" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="提现方式" prop="withdrawType">
              <el-select
                v-model="form.withdrawType"
                placeholder="请选择提现方式"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.withdrawTypeSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="发起提现的应用" prop="withdrawClientApp">
              <el-select
                v-model="form.withdrawClientApp"
                placeholder="请选择发起提现的应用"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.withdrawClientAppSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="提现金额（元）" prop="amount">
              <el-input-number
                v-model="form.amount"
                placeholder="请输入提现金额（元）"
                clearable
                style="width: 100%;"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="银行名称" prop="bankName">
              <el-input v-model="form.bankName" placeholder="请输入银行名称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserBankcardMain'
              })"
              >选择银行名称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="银行卡号" prop="bankcardNo">
              <el-input v-model="form.bankcardNo" placeholder="请输入银行卡号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserBankcardMain'
              })"
              >选择银行卡号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="提现状态" prop="withdrawStatus">
              <el-select
                v-model="form.withdrawStatus"
                placeholder="请选择提现状态"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="item in selects.withdrawStatusSelect"
                  :value="item.value"
                  :key="item.value"
                  :label="item.displayValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
            <el-form-item label="提现描述" prop="withdrawDescription">
              <el-input
                type="textarea"
                v-model="form.withdrawDescription"
                placeholder="请输入提现描述"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="审核人手机号" prop="checkedUserPhone">
              <el-input v-model="form.checkedUserPhone" placeholder="请输入审核人手机号" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择审核人手机号</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="审核人昵称" prop="checkedUserNickname">
              <el-input
                v-model="form.checkedUserNickname"
                placeholder="请输入审核人昵称"
                disabled
                clearable
              />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'UserMain'
              })"
              >选择审核人昵称</el-button>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="审核时间" prop="checkedTime">
              <el-date-picker
                type="datetime"
                v-model="form.checkedTime"
                placeholder="请输入审核时间"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%;"
                clearable
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
            <el-form-item label="完成时间" prop="completeTime">
              <el-date-picker
                type="datetime"
                v-model="form.completeTime"
                placeholder="请输入完成时间"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%;"
                clearable
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.edit = false">取消</el-button>
        <el-button type="primary" @click="edit" :loading="loading.edit">修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
import UploadImage from '@/components/Upload/UploadImage'
import Tinymce from '@/components/Tinymce'
const resUrl = process.env.VUE_APP_RES_URL
export default {
  name: 'FundsWithdrawAddEdit',
  components: {
    UploadImage,
    Tinymce,
  },
  data() {
    return {
      dialog: {
        add: false,
        edit: false,
      },
      loading: {
        add: false,
        edit: false,
      },
      form: {
        userId: undefined,
        userPhone: undefined,
        userNickname: undefined,
        userIsActive: undefined,
        orderNo: undefined,
        transactionNo: undefined,
        withdrawType: undefined,
        withdrawClientApp: undefined,
        amount: undefined,
        bankcardId: undefined,
        bankName: undefined,
        bankcardNo: undefined,
        withdrawStatus: undefined,
        withdrawDescription: undefined,
        checkedUserId: undefined,
        checkedUserPhone: undefined,
        checkedUserNickname: undefined,
        checkedUserIsActive: undefined,
        checkedTime: undefined,
        completeTime: undefined,
      },
      validateRules: {
        userId: [
          {
            type: 'integer',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        userPhone: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 11,
            message: '必须1-11个字符',
            trigger: 'blur',
          },
        ],
        userNickname: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 50,
            message: '必须1-50个字符',
            trigger: 'blur',
          },
        ],
        userIsActive: [
          {
            type: 'integer',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        orderNo: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 32,
            message: '必须1-32个字符',
            trigger: 'blur',
          },
        ],
        transactionNo: [
          {
            type: 'string',
            min: 1,
            max: 50,
            message: '必须1-50个字符',
            trigger: 'blur',
          },
        ],
        withdrawType: [
          {
            type: 'integer',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        withdrawClientApp: [
          {
            type: 'integer',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        amount: [
          {
            type: 'number',
            required: true,
            message: '此项为必须项',
            trigger: 'blur, change',
          },
        ],
        bankName: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 20,
            message: '必须1-20个字符',
            trigger: 'blur',
          },
        ],
        bankcardNo: [
          {
            type: 'string',
            required: true,
            message: '此项为必须项',
            trigger: 'blur',
          },
          {
            type: 'string',
            min: 1,
            max: 25,
            message: '必须1-25个字符',
            trigger: 'blur',
          },
        ],
        withdrawDescription: [
          {
            type: 'string',
            min: 1,
            max: 255,
            message: '必须1-255个字符',
            trigger: 'blur',
          },
        ],
        checkedUserPhone: [
          {
            type: 'string',
            min: 1,
            max: 11,
            message: '必须1-11个字符',
            trigger: 'blur',
          },
        ],
        checkedUserNickname: [
          {
            type: 'string',
            min: 1,
            max: 50,
            message: '必须1-50个字符',
            trigger: 'blur',
          },
        ],
      },
      dataDictCodes: [
        'YES_NO',
        'WITHDRAW_TYPE',
        'CLIENT_APP',
        'FUNDS_WITHDRAW_STATUS',
      ],
      selects: {
        userIsActiveSelect: [],
        withdrawTypeSelect: [],
        withdrawClientAppSelect: [],
        withdrawStatusSelect: [],
        checkedUserIsActiveSelect: [],
      },
      resUrl: resUrl,
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
  },
  methods: {
    initDataDict() {
      utils
        .getDataDict(this.dataDictCodes)
        .then((response) => {
          if (response) {
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'userIsActive',
              dataProp: 'userIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'WITHDRAW_TYPE',
              formProp: 'withdrawType',
              dataProp: 'withdrawTypeSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'CLIENT_APP',
              formProp: 'withdrawClientApp',
              dataProp: 'withdrawClientAppSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'FUNDS_WITHDRAW_STATUS',
              formProp: 'withdrawStatus',
              dataProp: 'withdrawStatusSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'checkedUserIsActive',
              dataProp: 'checkedUserIsActiveSelect',
            })
          }
        })
        .catch((error) => {})
    },
    dialogClosed(formRef) {
      this.$refs[formRef].resetFields()
      for (let key in this.form) {
        this.form[key] = undefined
      }
    },
    add() {
      this.$emit('add')
    },
    edit() {
      this.$emit('edit')
    },
    /** 触发父组件展示关联表数据的搜索对话框 */
    showJoinSearch(options) {
      this.$emit('showJoinSearchDialog', options)
    },
    imgUploadSuccess(formProp, url) {
      this.form[formProp] = url
    },
    imgRemoveSuccess(formProp) {
      this.form[formProp] = undefined
    },
  },
}
</script>

<style>
</style>